package com.sc.service.goods;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sc.dal.dto.goods.GoodsClassMap;
import com.sc.dal.mapper.goods.GoodsClassMapper;
import com.sc.dal.model.goods.GoodsClass;

/**
 * 商品分类服务实现
 * @author maoyongbin
 * @日期 Mar 13, 2017 9:13:56 AM
 */
@Service
public class GoodsClassService {

	@Autowired
	private GoodsClassMapper goodsClassMapper;
	
	/**
	 * 根据id，查找商品分类
	 * @param id
	 * @return GoodsClass
	 */
	public GoodsClass selectByPrimaryKey(Integer id){
		GoodsClass goodsClass = this.goodsClassMapper.selectByPrimaryKey(id);
		
		return goodsClass;
	}
	
	/**
	 * 查找所有商品分类
	 * @return List<GoodsClass>
	 * @param paramMap
	 */
	public List<GoodsClass> selectList(Map<String,Object> paramMap){
		List<GoodsClass> goodsClassList = this.goodsClassMapper.selectList(paramMap);
		
		return goodsClassList;
	}
	/**
	 * 查找所有商品分类
	 * @return List<GoodsClass>
	 * @param paramMap
	 */
	public List<GoodsClassMap>  queryGoodsClassList(Map<String,Object> paramMap){
		List<GoodsClassMap>  goodsClassList = this.goodsClassMapper.queryGoodsClassList(paramMap);
		return goodsClassList;
	}
	/**
	 * 查找商品一级分类
	 * @return List<GoodsClass>
	 * @param paramMap
	 *  pc端  首页展示
	 * 
	 */
	public List<GoodsClass> selectByGoodsClass(){
		List<GoodsClass> goodsClassList = this.goodsClassMapper.selectByGoodsClass();
		for (GoodsClass goodsClass : goodsClassList) {
			Integer id = goodsClass.getId();
			//二级页面
			if(id!=null){
				List<GoodsClass> parentList = goodsClassMapper.queryParentList(id);
				goodsClass.setChildren(parentList);
				//三级页面信息
				if (parentList!=null && parentList.size()>0) {
					for (GoodsClass goodsClass2 : parentList) {
						Integer id2 = goodsClass2.getId();
						List<GoodsClass> parentList2 = goodsClassMapper.queryParentList(id2);
						goodsClass2.setChildren(parentList2);
					}
				}
			}
			
		}
		
		
		return goodsClassList;
	}
	
	
	
	/**
	 * 查找商品分类
	 * @return List<GoodsClass>
	 * @param paramMap
	 *  微信端  首页进入列表  分类展示
	 * 
	 */
	public List<GoodsClass> selectByWxGoodsClass(Integer id){
		//二级页面
		List<GoodsClass> parentList = goodsClassMapper.queryParentList(id);
		//三级页面信息
		if (parentList!=null && parentList.size()>0) {
			for (GoodsClass goodsClass2 : parentList) {
				Integer id2 = goodsClass2.getId();
				List<GoodsClass> parentList2 = goodsClassMapper.queryParentList(id2);
				goodsClass2.setChildren(parentList2);
			}
		}
		return parentList;
	}
	
	
	public int editGoodsClassStatus(List<Long> ids){
		this.goodsClassMapper.updateNotStatus(ids);
		int i = goodsClassMapper.updateStatus(ids);
		return i;
	}
	
	/***
	 * 插入商品分类
	 * @param goodsClass
	 * @return
	 */
	public int insertGoodsClass(GoodsClass goodsClass){
		return goodsClassMapper.insert(goodsClass);
	}
	
	/***
	 * 更新商品分类
	 * @param goodsClass
	 * @return
	 */
	public int updateGoodsClass(GoodsClass goodsClass){
		return goodsClassMapper.updateByPrimaryKey(goodsClass);
	}
	
	
	
	/**
	 * 
	 * pc端 首页获取数据
	 * 查找商品分类
	 * @return List<GoodsClass>
	 * @param paramMap
	 *  pc端  首页展示
	 * 
	 */
	public List<GoodsClass> selectByGoodsClassList(Integer id){
		List<GoodsClass> parentList = goodsClassMapper.queryParentList(id);
		return parentList;
	}
	
}
